package com.itheima.demo01;

import java.io.*;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Consumer;

public class ByteBufferStream01 {
    public static void main(String[] args) throws IOException {
        //字符缓冲流

        //利用字符流 读取文件内容 重新排序之后写入新的文件中
        BufferedReader br = new BufferedReader(new FileReader("a.txt"));

        String len;

        TreeMap<Integer,String> tm = new TreeMap<>();

        while ((len = br.readLine()) != null){
            String[] st = len.split("\\.");
            tm.put(Integer.parseInt(st[0]),len);
        }

        BufferedWriter bw = new BufferedWriter(new FileWriter("result1.txt"));

        Set<Map.Entry<Integer, String>> entries = tm.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            bw.write(entry.getValue());
            bw.newLine();
        }

        //关闭流
        br.close();

        bw.close();
    }

}
